package net.yambal.android.infomation;

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ArrayAdapterInfomation extends ArrayAdapter<InfomationItem> {
	private int _textViewResourceId;
	private List<InfomationItem> _items;
	private LayoutInflater _inflater;
	
	public ArrayAdapterInfomation(Context context, int textViewResourceId, List<InfomationItem> items) {
		super(context, textViewResourceId, items);
		_textViewResourceId = textViewResourceId;
		_items = items;
		_inflater = (LayoutInflater)context.getSystemService(
				Context.LAYOUT_INFLATER_SERVICE
		);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		if(convertView == null){
			convertView = _inflater.inflate(_textViewResourceId, null);
		}
		final InfomationItem item = _items.get(position);
		if(item != null){
			TextView info = (TextView)convertView.findViewWithTag("textViewInfomation");
			info.setText(item.infomation);
			
			TextView label = (TextView)convertView.findViewWithTag("textViewLabal");
			label.setText(item.info_label);
		}
		return convertView;
	}
	
	@Override
    public InfomationItem getItem(int position) {
      return _items.get(position);
    }
	
	@Override
    public int getCount() {
      return _items.size();
    }
	
	@Override
    public long getItemId(int position) {
      return position;
    }
}
